/*
 * Emprestimo.java
 *
 * Created on 21/10/2011, 01:22:58
 */
package org.acervus.gui;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import org.acervus.emprestimo.EmprestimoBean;
import org.acervus.operador.OperadorBean;

/**
 *
 * @author Eziel Soares, Giordano Giuliano, Lenilson Regis
 */

public class Emprestimo extends javax.swing.JFrame {
    
    DefaultTableModel tmEmprestimo = new DefaultTableModel(null, new String[]{"Título", "Autor", "Tipo"});
    ListSelectionModel lsmEmprestimo;
    List<EmprestimoBean> emprestimo;
    private OperadorBean operadorLogado;
    String tipoCadastro;
    Date data;
    String dataAtual;

    /** Creates new form Emprestimo */
    public Emprestimo() {
        initComponents();
    }
    
    private void tbEmprestimoLinhaSelecionada() {
        if (tbEmprestimo.getSelectedRow() != -1) {
            
        }
    }
    
    BuscarUsuario buscarusuario;
    BuscarAcervo buscaracervo;
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        tfDataRetirada = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfDataEntrega = new javax.swing.JTextField();
        tfBuscarUsuário = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btBuscarUsu = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbEmprestimo = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        tfBuscarAcervo = new javax.swing.JTextField();
        btBuscarAce = new javax.swing.JButton();
        btFechar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        btAtualizar = new javax.swing.JButton();

        jLabel6.setText("jLabel6");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Empréstimo");

        jLabel1.setText("Data de Retirada:");

        tfDataRetirada.setEnabled(false);
        data = new Date();
        dataAtual = new SimpleDateFormat("dd/MM/yyyy").format(data);
        tfDataRetirada.setText(dataAtual);

        jLabel2.setText("Data de Entrega:");

        tfDataEntrega.setEnabled(false);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime( new Date() );
        calendar.add( Calendar.DAY_OF_MONTH , 7 );
        tfDataEntrega.setText( new SimpleDateFormat("dd/MM/yyyy").format( calendar.getTime() ));

        jLabel4.setText("Usuário:");

        btBuscarUsu.setText("Buscar");
        btBuscarUsu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBuscarUsuActionPerformed(evt);
            }
        });

        jLabel5.setText("Empréstimo");

        tbEmprestimo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tbEmprestimo.setModel(tmEmprestimo);
        tbEmprestimo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmEmprestimo = tbEmprestimo.getSelectionModel();
        lsmEmprestimo.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    tbEmprestimoLinhaSelecionada();
                }
            }
        });
        jScrollPane1.setViewportView(tbEmprestimo);

        jLabel3.setText("Acervo:");

        btBuscarAce.setText("Buscar");
        btBuscarAce.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBuscarAceActionPerformed(evt);
            }
        });

        btFechar.setText("Fechar");

        btCancelar.setText("Cancelar");

        btAtualizar.setText("Finalizar Empréstimo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfDataRetirada, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel4))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tfDataEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(tfBuscarUsuário, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btBuscarUsu))))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfBuscarAcervo, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btBuscarAce, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btAtualizar)
                        .addGap(279, 279, 279)
                        .addComponent(btCancelar)
                        .addGap(13, 13, 13)
                        .addComponent(btFechar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfDataRetirada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfDataEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfBuscarUsuário, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btBuscarUsu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfBuscarAcervo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btBuscarAce))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelar)
                    .addComponent(btFechar)
                    .addComponent(btAtualizar))
                .addContainerGap(47, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mostrarBuscarUsuario() {

        if (buscarusuario == null) {
            buscarusuario = new BuscarUsuario();
            buscarusuario.setVisible(true);
        } else {
            buscarusuario.setVisible(true);
            buscarusuario.setState(JFrame.NORMAL);
        }

    }
    
    private void btBuscarUsuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBuscarUsuActionPerformed
        mostrarBuscarUsuario();
    }//GEN-LAST:event_btBuscarUsuActionPerformed

    
    private void mostrarBuscarAcervo() {

        if (buscaracervo == null) {
            buscaracervo = new BuscarAcervo();
            buscaracervo.setVisible(true);
        } else {
            buscaracervo.setVisible(true);
            // buscaracervo.setState(JFrame.NORMAL);
        }

    }
    
    private void btBuscarAceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBuscarAceActionPerformed
        mostrarBuscarAcervo();
    }//GEN-LAST:event_btBuscarAceActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Emprestimo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Emprestimo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Emprestimo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Emprestimo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Emprestimo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAtualizar;
    private javax.swing.JButton btBuscarAce;
    private javax.swing.JButton btBuscarUsu;
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btFechar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbEmprestimo;
    private javax.swing.JTextField tfBuscarAcervo;
    private javax.swing.JTextField tfBuscarUsuário;
    private javax.swing.JTextField tfDataEntrega;
    private javax.swing.JTextField tfDataRetirada;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the operadorLogado
     */
    public OperadorBean getOperadorLogado() {
        return operadorLogado;
    }

    /**
     * @param operadorLogado the operadorLogado to set
     */
    public void setOperadorLogado(OperadorBean operadorLogado) {
        this.operadorLogado = operadorLogado;
    }
}
